<template>
  <div>
    <br>
    <el-table v-loading="loading" :data="showData()" style="width: 100%" height="340">
      <el-table-column fixed prop="id" label="ID" width="140" />
      <el-table-column prop="actualPrice" label="Univalence" width="140" />
      <el-table-column prop="dtitle" label="ProductName" width="200" />
      <el-table-column prop="createTime" label="ProductDate" width="280" />
      <el-table-column prop="title" label="PhoneIntroduce" width="320" />
    </el-table>
    <br>
    <div class="public">
      <div class="demo-pagination-block">
        <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[5, 10, 15, 20]"
          :small="small" :disabled="disabled" :background="background" layout="total, sizes, prev, pager, next, jumper"
          :total="showarr.length" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed, getCurrentInstance, watch } from 'vue';
import { reactive, ref } from 'vue'
// import { useStore } from 'vuex'
// const store = useStore()


let currentPage = ref(1)//默认页面
let pageSize = ref(5)//每页条数
let small = ref(false)
let background = ref(false)
let disabled = ref(false)


const loading = ref(true)

// axios请求
const { proxy } = getCurrentInstance()
let showarr = reactive([])
proxy.$api
  .get(
    'http://openapiv2.dataoke.com/open-api/goods/list-super-goods?type=0&pageId=1&pageSize=56&keyWords=%E6%89%8B%E6%9C%BA&appKey=622b674f76e31'
  )
  .then((val) => {
    showarr.push(...val.data.data.list)
    showData()
    loading.value=false
  })

watch('showarr', (val) => {
  console.log(val);
})
function showData() {
  return showarr.slice((currentPage.value - 1) * pageSize.value, currentPage.value * pageSize.value)
}

</script>

<style lang="less" scoped>
.public {
  width: 85vw;
  height: 7vh;

  // outline: 1px solid red;
  .demo-pagination-block {
    position: absolute;
    left: 380px;
  }
}
</style>